// 一些通用的声明和定义
#ifndef _COMMON_H
#define _COMMON_H
#include "riscv.h"

struct spinlock;
struct proc;
struct context;

#define NCPU             8    //CPU的最大数量
#define NPROC            64   //进程的最大数量


// QEMU模拟的RISC-V虚拟机的关机设备地址
#define QEMU_POWER_REG 0x100000L
#define QEMU_POWER_OFF 0x5555  // 关机命令值

void shutdown(void);       // 关机

// kalloc.c
void kinit(void);
void* kalloc(void);
void kfree(void *pa);

// vm.c
void kvminit(void);
void kvminithart(void);
int mappage(pagetable_t pagetable, uint64 va, uint64 pa, uint64 size, int perm);
void kvmmap(pagetable_t pagetable, uint64 va, uint64 pa, uint64 size, int perm);
pte_t* walk(pagetable_t pagetable, uint64 va, int alloc);
void uvmunmap(pagetable_t pagetable, uint64 va, uint64 size, int isfree);
void uvmfree(pagetable_t pagetable, uint64 size);
pagetable_t uvmmake();
void uvmfirst(pagetable_t pagetable, uint8 *, uint32);


// trap.c
void trapinithart(void);
void usertrapret(void);

// uart.c
void uartinit(void);
void uartputc(char c);
void uartputs(const char *s);
char uartgetc(void);
void uartgets(char *buf);


// console.c
void consputc(char c);

// printf.c
// void printint(int num, int base, int sign);
// void printptr(unsigned long ptr);
int printf(char *fmt, ...);
void panic(char *s);
void printfinit(void);

// spinlock.c
void initlock(struct spinlock *lk, char* name);
void acquire(struct spinlock *lk);
void release(struct spinlock *lk);
void intr_push(void);
void intr_pop(void);
// proc.c
struct cpu* getcpu(void);
struct proc* getproc(void);
void procinit(void);
void procinituser(void);
void scheduler(void);
void procstacksmap(pagetable_t pagetable);
int killed(struct proc *p);
void exit(int status);
// swtch.S
void swtch(struct context*, struct context*);

// syscall.c
void syscall(void);
// string.c
void* memset(void* dst, uint32 c, uint32 n);
void* memmove(void *dst, const void *src, uint32 n);

#endif